import Toast from '../miniprogram_npm/@vant/weapp/toast/toast';
import * as Storage from '../utils/storage';
import {
	joinUrl,
	makeRandom
} from '../utils/util';
const md5 = require('../utils/md5');
// const upload = require("../libs/oss/upload.js")
const {
	baseURL,
	kiccBaseUrl,
	defaultShenyuContextPath
} = require('../env');

/**
 *  异步请求提封装 防止回调地狱 Create by lsx 2022年5月30日
 */
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
/**
 * 带token请求体封装
 * @param {请求方式} method
 * @param {请求路径} url
 * @param {请求所需参数} data
 * @returns
 */
function request(method, url, data, options = {}) {
	// 这里定义一个requestTask用来接收里面的wx.request,wx.request的返回值可以中断请求
	let requestTask = '';
	const res = new Promise(function (resolve, reject) {
		const accessToken = wx.getStorageSync(Storage.ACCESS_TOKEN);
		const header = {
			'content-type': 'application/json',
			accessToken: accessToken ? accessToken + ':' + Storage.APPID : ''
		};
		// https://shenyu.apache.org
		/** 处理神禹网关多个服务动态路由地址 */
		let urlPrefix = baseURL;
		if (options.shenyuContextPath) {
			urlPrefix = joinUrl(urlPrefix, options.shenyuContextPath);
		} else {
			urlPrefix = joinUrl(urlPrefix, defaultShenyuContextPath);
		}

		wx.request(
			Object.assign({
					// joinUrl(urlPrefix, url)
					url: options.url ? options.url : joinUrl(urlPrefix, url),
					method: method,
					data: method === POST ? JSON.stringify(data) : data, // POST请求需转成JSON格式
					header: header,
					success(res) {
						// 根据请求响应码status 判断请求结果
						if (res.data.code == 200 || res.data.status === 0) {
							resolve(res);
						} else if (res.data.status == 301) {
							// 状态为301的时候且是需要登录才能进去的页面那么就去登录页面
							let openId = wx.getStorageSync('user_open_id');
							let version = wx.getStorageSync('version');
							// tonken失效就删除进入首页
							wx.clearStorage({
								success: res => {
									// 清除本地存储，有openId就需要保存起来
									if (openId) wx.setStorageSync('user_open_id', openId);
									wx.setStorageSync('version', version);
									wx.reLaunch({
										url: '/subcontract/person/pages/login/login/index'
									});
								}
							});
							return;
						} else {
							// 其它异常，吊起提示 1.5秒后 返回异常操作
							Toast.fail(res.data.msg ? res.data.msg : res.data.error);
							reject(res.data || res.error);
						}
					},
					fail(err) {
						// 返回网络异常提示
						Toast.fail('请求异常');
					}
				},
				options
			)
		);
	});
	res.requestTask = requestTask;
	return res;
}

/**
 * 不带token请求体封装
 * @param {请求方式} method
 * @param {请求路径} url
 * @param {请求参数} data
 */
function request_v(method, url, data, options = {}) {
	return new Promise(function (resolve, reject) {
		const header = {
			'content-type': 'application/json'
		};

		// https://shenyu.apache.org
		/** 处理神禹网关多个服务动态路由地址 */
		let urlPrefix = baseURL;
		if (options.shenyuContextPath) {
			urlPrefix = joinUrl(urlPrefix, options.shenyuContextPath);
		} else {
			urlPrefix = joinUrl(urlPrefix, defaultShenyuContextPath);
		}

		wx.request({
			url: options.url ? options.url : joinUrl(urlPrefix, url),
			method: method,
			data: method === POST ? JSON.stringify(data) : data, // POST请求需转成JSON格式
			header: header,
			success(res) {
				// 根据请求响应码status 判断请求结果
				if (res.data.status === 0) {
					resolve(res);
				} else {
					// 其它异常，吊起提示 1.5秒后 返回异常操作
					Toast.fail(res.data.msg);
					reject(res.data);
				}
			},
			fail(err) {
				// 返回网络异常提示
				Toast.fail('请求异常');
			}
		});
	});
}

/**
 *  文件上传
 * @param {路径} url
 * @param {文件} filePath
 * @param {请求参数} formData
 */

function uploadFile(url, filePath, formData = {}, options = {}) {
	return new Promise((resolve, reject) => {
		wx.uploadFile(
			Object.assign({
					filePath: filePath,
					name: 'file',
					url: baseURL + url,
					formData,
					success: res => {
						res = JSON.parse(res.data);
						if (res.code == 200) {
							resolve(res);
						} else {
							Toast.fail(res.msg);
							reject(res);
						}
					},
					fail: err => {
						Toast.fail(err);
						reject(err);
					}
				},
				options
			)
		);
	});
}

/**
 * oss上传文件
 */
function request_oss(filePath) {
	return new Promise(function (resolve, reject) {
		// const header = {
		// 	'content-type': 'application/json',
		// 	accessToken: wx.getStorageSync(Storage.ACCESS_TOKEN)
		// }
		// wx.showLoading({ title: '加载中', mask: true })
		wx.request({
			url: 'http://192.168.3.60:8069/aliyun/sts/token',
			method: 'GET',
			// data: JSON.stringify(data), // POST请求需转成JSON格式
			// header: header,
			success(res) {
				let data = res.data.data;
				data.filePath = filePath;
				// 根据请求响应码status 判断请求结果
				if (res.data.status === 0) {
					wx.hideLoading();
					upload(data)
						.then(res => {
							resolve(res);
						})
						.catch(err => {
							reject(err);
						});
					// return
					// wx.uploadFile({
					//   url: "https://kl-lab.oss-cn-hangzhou.aliyuncs.com", // 开发者服务器的URL。
					//   header:{
					//     "Content-Type":"multipart/form-data"
					//   },
					//   filePath: filePath,
					//   name: 'file', // 必须填file。
					//   formData: {
					//     // name:filePath,
					//     key:'wx/'+uploadFilePath,
					//     AccessKeySecret:res.data.data.accessKeySecret,
					//     OSSAccessKeyId: res.data.data.accessKeyId,
					//     // signature:"12321",
					//     // policy:"13131232",
					//     securityToken:res.data.data.securityToken,
					//     // 'x-oss-security-token': res.data.data.securityToken // 使用STS签名时必传。
					//   },
					//   success: (res) => {
					//     console.log(res,131)
					//     if (res.statusCode === 204) {
					//       console.log('上传成功');
					//       resolve(res)
					//     }
					//   },
					//   fail: err => {
					//     console.log(err);
					//     reject(res.data)
					//   }
					// });
				} else {
					// 其它异常，吊起提示 1.5秒后 返回异常操作
					Toast.fail(res.data.msg);
					setTimeout(function () {
						wx.hideLoading();
					}, 1500);
				}
			},
			fail(err) {
				// 返回网络异常提示
				wx.hideLoading();
				Toast.fail('请求异常');
			}
		});
	});
}

/**
 * 限制重复提交 - POST
 * @param {*} method
 * @param {*} url
 * @param {*} data
 */

function requset_add_repeats(method, url, data) {
	return new Promise(function (resolve, reject) {
		const header = {
			'content-type': 'application/json',
			accessToken: wx.getStorageSync(Storage.ACCESS_TOKEN)
		};
		wx.showLoading({
			title: '加载中',
			mask: true
		});
		wx.request({
			url: baseURL + url,
			method: method,
			data: JSON.stringify(data), // POST请求需转成JSON格式
			header: header,
			success(res) {
				// 根据请求响应码status 判断请求结果
				if (res.data.status === 0) {
					setTimeout(() => {
						wx.hideLoading();
						resolve(res);
					}, 3000);
				} else {
					// 其它异常，吊起提示 1.5秒后 返回异常操作
					Toast.fail(res.data.msg);
					setTimeout(function () {
						wx.hideLoading();
						reject(res.data);
					}, 3000);
				}
			},
			fail(err) {
				// 返回网络异常提示
				wx.hideLoading();
				Toast.fail('请求异常');
			}
		});
	});
}
/**
 *
 */
const API = {
	// 通过wxCode获取OpenId*
	getOpenId: data => request_v(GET, 'wx/v1/auth/getOpenId', data),
	// 注册
	customerRegister: data => request_v(POST, 'wx/v1/customer/customerRegister', data),
	// 获取验证码
	getPhoneCode: data => request_v(POST, 'wx/v1/msg/sms', data),
	// 登录
	userLogin: data => request_v(POST, 'wx/v1/user/userLogin', data),
	// 退出登录
	userLoginOut: data => request(POST, 'wx/v1/user/userLoginOut', data),
	// 忘记密码
	forgetPassword: data => request_v(POST, 'wx/v1/user/forgetPassword', data),
	// 获取手机号
	getPhone: data => request_v(GET, 'wx/v1/auth/getPhone', data),
	//获取头像和昵称
	getNickName: data => request_v(GET, 'wx/v1/user/getNickName', data),
	// 获取绑定的手机号
	getUserPhone: data => request(GET, 'wx/v1/user/getUserPhone', data),
	// 设置绑定手机号
	setUserPhone: data => request(PUT, 'wx/v1/user/setUserPhone', data),
	// 获取呼叫器列表
	listBeeperByCustomer: data => request(GET, 'wx/v1/equip/listEquipByCustomer', data),
	// 获取呼叫器详情
	getBeeper: data => request(GET, 'wx/v1/beeper', data),
	// 获取呼叫器部分信息
	getPortionInfo: data => request(GET, 'wx/v1/beeper/getPortionInfo', data),
	// 获取呼叫器的主用户
	getBeeperCustomer: data => request(GET, 'wx/v1/customer/listIdName', data),
	// 根据栋单元层查找呼叫器下的居民
	getResidentList: data => request(GET, 'wx/v1/customer/pageNoMain', data),
	// 通过层获取门牌号
	getHouseNumberByFloorId: data => request(GET, 'wx/v1/userHarvestAddress/listHouseNumber', data),
	// 通知发送
	notifySend: data => request(POST, 'wx/v1/customer/noticeNoMain', data),
	// 新增呼叫器标签
	tagAdd: data => request(POST, 'wx/v1/beeperTag', data),
	// 连接wifi
	getWifiInfo: data => request(GET, 'wx/v1/beeperExtend/getData', data),
	// 删除呼叫器标签
	tagDelete: data => request(PUT, 'wx/v1/beeperTag/delete', data),
	// 用户（呼叫器）地址修改
	setBeeperAddress: data => request(PUT, 'wx/v1/userHarvestAddress', data),
	// 查询余额
	getBeeperBalance: data => request(GET, 'wx/v1/beeper/getBeeperBalance', data),
	// 查询充值套餐
	comboInfo: data => request(GET, 'wx/v1/comboInfo/listAll', data),
	// 呼叫器充值
	rechargePay: data => request(POST, 'wx/v1/beeper/rechargePay', data),
	// 账单列表
	beeperBill: data => request(GET, 'wx/v1/beeperBill/page', data),
	// 订单列表
	orderList: data => request(GET, 'wx/v1/order/page', data),
	// 获取订单导入的地址
	getOrderExportUrl: data => request(GET, 'wx/v1/order/exportOrder', data),
	// 检验外送或者影像预约的查询结果
	listKlabReportUrl: data => request(GET, 'wx/v1/order/listKlabReportUrl', data),
	// 收入明细列表
	orderSplitList: data => request(GET, 'wx/v1/orderSplitInfo/page', data),
	// 单个收入明细信息
	orderSplitInfo: data => request(GET, 'wx/v1/orderSplitInfo', data),
	// 最近的一笔订单信息
	getRecentOrder: data => request(GET, 'wx/v1/order/getRecentlyData', data),
	// 订单详情
	orderDetail: data => request(GET, 'wx/v1/order', data),
	// 取消订单
	cancelOrder: data => request(PUT, 'wx/v1/order/cancelOrder', data),
	// 评价订单
	evaluationOrder: data => request(PUT, 'wx/v1/order/evaluate', data),
	// 服务员查看待支付订单的二维码
	getPayWxUrlById: data => request(GET, 'wx/v1/beeper/getPayWxUrlById', data),
	// 修改价格
	orderChangePrice: data => request(PUT, 'wx/v1/order/orderChangePrice', data),
	// 绑定呼叫器
	scanCodeBinding: data => request(POST, 'wx/v1/customer/scanCodeBinding', data),
	// 服务员列表
	waiterList: data => request(GET, 'wx/v1/waiter/listIdName', data),
	// 服务员列表-分页
	waiterListPage: data => request(GET, 'wx/v1/waiter/page', data),
	// 新增服务员
	addWaiter: data => request(POST, 'wx/v1/waiter', data),
	// 商家接单
	takeOrders: data => request(PUT, 'wx/v1/order/takeOrders', data),
	// 订单操作-服务员
	orderOperate: data => request(PUT, 'wx/v1/order/orderOperate', data),
	// 解绑设备
	unbindBinding: data => request(PUT, 'wx/v1/customer/unbindBinding', data),
	// 设备解除警报
	equipAllClear: data => request(PUT, 'wx/v1/equip/equipAllClear', data),
	// 订单解除警报
	orderCancelAlarm: data => request(PUT, 'wx/v1/order/orderCancelAlarm', data),
	// 设置商户位置
	setBusinessAddress: data => request(PUT, 'wx/v1/business/setBusinessAddress', data),
	// 获取商户位置
	getBuisnessInfo: data => request(GET, 'wx/v1/business', data),
	// 获取商户列表
	getBuisnessList: data => request(GET, 'wx/v1/business/listIdNameVo', data),
	// 通过搜索获取商户列表数据
	getBusinessByName: data => request(GET, 'wx/v1/beeperBtn/getBusinessByName', data),
	// 获取商户首页数据
	getShopData: data => request(GET, 'wx/v1/business/businessHomePage', data),
	// 获取商户接收器
	getReceiverList: data => request(GET, 'wx/v1/receiver/listReceiverByBusiness', data),
	// 绑定接收器
	receiverBinding: data => request(POST, 'wx/v1/business/receiverBinding', data),
	// 解绑接收器
	busunbindBinding: data => request(PUT, 'wx/v1/business/unbindBinding', data),
	// 订单统计数据
	getStatisticsData: data => request(GET, 'wx/v1/business/getStatisticsData', data),
	// 获取服务员首页数据
	waiterHomePage: data => request(GET, 'wx/v1/waiter/waiterHomePage', data),
	// 修改营业状态
	updateBusinessState: data => request(PUT, 'wx/v1/business/updateBusinessState', data),
	// 服务列表
	getServiceList: data => request(GET, 'wx/v1/beeper/listServerBtn', data),
	// 查询所有服务
	getAllService: data => request(GET, 'wx/v1/serverClassify/listCheckoutData', data),
	getTagService: data => request(GET, 'wx/v1/serverClassify/listIdName', data),

	// 获取二三级服务
	getTwoServerList: data => request(GET, 'wx/v1/serverClassify/idNameTree', data),
	// 根据服务类型查询商户
	listIdNameByClassifyId: data => request(GET, 'wx/v1/business/listIdNameByClassifyId', data),
	// 根据服务类型和商户查出服务内容列表
	listServerBtn: data => request(GET, 'wx/v1/businessServer/listServer', data),
	// 保存修改的服务
	updateServerBtn: data => request(PUT, 'wx/v1/beeper/updateServerBtn', data),
	// 商户注册
	businessRegister: data => request(POST, 'wx/v1/business/businessRegister', data),
	// 商户绑定呼叫器
	shopScanCodeBinding: data => request(POST, 'wx/v1/business/beeperBinding', data),
	// 查询该商户下所有的接收器
	listReceiverByBusiness: data => request(GET, 'wx/v1/receiver/listReceiverByBusiness', data),
	// 查询该商户下所有的接收器
	listBeeperByBusiness: data => request(GET, 'wx/v1/beeper/listBeeperByBusiness', data),
	// 商户查询自己的服务集合
	listBusinessServer: data => request(GET, 'wx/v1/businessServer/listBusinessServer', data),
	// 商户新增服务
	shopAddService: data => request(POST, 'wx/v1/businessServer', data),
	// 商户修改服务
	shopUpdateService: data => request(PUT, 'wx/v1/businessServer', data),
	// 商户解绑呼叫器
	beeperUnbindBinding: data => request(PUT, 'wx/v1/business/beeperUnbindBinding', data),
	// 扫码支付
	scanToPayWaitOrder: data => request(GET, 'wx/v1/order/scanToPayWaitOrder', data),
	// 查询呼叫器最新的订单
	getWaitPayOrder: data => request(GET, 'wx/v1/order/getWaitPayOrder', data),
	// 历史订单
	pageHistory: data => request(GET, 'wx/v1/order/pageHistory', data),
	// 查询最近未支付订单
	listWaitPayOrder: data => request(GET, 'wx/v1/order/listWaitPayOrder', data),
	// 支付最近未支付订单
	beeperBalancePay: data => request(PUT, 'wx/v1/order/beeperBalancePay', data),
	// 退款
	saleReturn: data => request(PUT, 'wx/v1/order/salesReturn', data),
	// 消息列表
	messageList: data => request(GET, 'wx/v1/remind/page', data),
	// 查询是否注册
	getByOpenId: data => request(GET, 'wx/v1/user/checkoutUserRegister', data),
	// 根据场所获取用户列表(除了自己)
	listCustomerByLocaleId: data => request(GET, 'wx/v1/customer/listCustomerByLocaleId', data),
	// 根据场所获取用户列表(包括自己)
	listUserCustomer: data => request(GET, 'wx/v1/customer/listUserCustomer', data),
	// 授权和解绑
	customerOperation: data => request(PUT, 'wx/v1/customer/customerOperation', data),
	// 转让权
	customerMakeOver: data => request(PUT, 'wx/v1/customer/customerMakeOver', data),
	// 获取已注册的角色
	listUserByOpenId: data => request(GET, 'wx/v1/user/listUserByOpenId', data),
	// 切换角色
	getUserByRegisterOpenId: data => request(GET, 'wx/v1/user/switchUserByOpenId', data),
	// 设置用户信息
	setUserInfo: data => request(PUT, '/wx/v1/user/setUserInfo', data),
	// 获取呼叫器是否有主用户
	checkoutEquipBinding: data => request(PUT, 'wx/v1/customer/checkoutEquipBinding', data),
	// 燃气报警器详情
	getBeeperR: data => request(GET, 'wx/v1/gas', data),
	// 燃气报警器详情
	gasUpdateValveState: data => request(GET, 'wx/v1/gas/updateValveState', data),
	// 烟雾报警器详情
	getBeeperY: data => request(GET, 'wx/v1/smoke', data),
	// 跌倒报警器详情
	getBeeperD: data => request(GET, 'wx/v1/radar', data),
	// SOS报警器详情
	getBeeperS: data => request(GET, 'wx/v1/sos', data),
	// 摄像头详情
	getBeeperC: data => request(GET, 'wx/v1/camera', data),
	// 水浸卫士详情
	getBeeperW: data => request(GET, 'wx/v1/waterFlood', data),
	// 门禁详情
	getBeeperM: data => request(GET, 'wx/v1/doorLock', data),
	// 红外探测器详情
	getBeeperH: data => request(GET, 'wx/v1/infrared', data),
	// 睡眠监测仪详情
	getBeeperL: data => request(GET, 'wx/v1/sleep', data),
	// 获取睡眠详情
	getByDeviceId: data => request(GET, 'wx/v1/sleepDeviceConfig/getByDeviceId/' + data),
	setAlarmMode: data => request(PUT, 'wx/v1/infrared/setAlarmMode', data),
	// 血糖仪详情
	getBeeperG: data => request(GET, 'wx/v1/sugar', data),
	// 血糖仪报告
	sugarReport: data => request(GET, 'wx/v1/sugarDetection/' + data, data),
	// 血糖仪报告列表
	sugarReportList: data => request(GET, 'wx/v1/sugarDetection/list', data),
	// 确定血糖仪的使用人
	updateSugarUser: data =>
		request(PUT, 'wx/v1/sugarDetection/updateByUserId?userId=' + data.userId + '&deviceId=' + data.deviceId),
	// 通过用户id查询血糖仪报告列表
	getSugarListByUserId: data => request(GET, 'wx/v1/sugarDetection/listByUserId', data),
	// 血压仪详情
	getBeeperP: data => request(GET, 'wx/v1/pressure', data),
	// 动态血压仪详情
	getBeeperDP: data => request(GET, 'wx/v1/dynamicPressure', data),
	// 智能拐杖仪详情
	getBeeperSC: data => request(GET, 'wx/v1/crutch', data),
		// 定位鞋详情
		getBeeperLS: data => request(GET, 'wx/v1/shoes', data),
	// 胸牌详情
	getBeeperNB: data => request(GET, 'wx/v1/badge', data),
	// 智护手表
	getBeeperSW: data => request(GET, 'wx/v1/watch', data),
	//  设置一些安全设备的联系人联系电话
	setSafeEquipContact: data => request(POST, 'wx/v1/equipContact/setEquipContact', data),
	//设置呼叫器通讯录
	setBeeperContact: data => request(POST, 'wx/v1/equipContact/setBeeperContact', data),
	// 获取一些安全设备的联系人联系电话
	getSafeEquipContact: data => request(GET, 'wx/v1/equipContact/getDataByEquipId', data),
	// // 血压仪报告
	// pressureReport: data => request(GET, 'wx/v1/pressireDetection/'+data, data),
	// // 血压仪报告列表
	// pressureReportList: data => request(GET, 'wx/v1/pressureDetection/list',data),
	// // 确定血压仪的使用人
	// updatePressureUser: data => request(PUT, 'wx/v1/pressureDetection/updateByUserId?userId='+data.userId+'&deviceId='+data.deviceId),
	//  // 通过用户id查询血压仪报告列表
	//  getPressureListByUserId: data => request(GET, 'wx/v1/pressureDetection/listByUserId',data),
	// 报警记录
	warningRecord: data => request(GET, 'wx/v1/equipLog/alarm/page', data),
	// 设置所属关系
	setCustomerRelative: data => request(PUT, 'wx/v1/customer/setCustomerRelative', data),
	// 判断呼叫器是否已绑定
	getEquipInfo: data => request(POST, 'wx/v1/customer/getEquipInfo', data),
	// 场所列表
	localeList: data => request(GET, 'wx/v1/locale/listIdName', data),
	// 场所详情
	localeDetails: data => request(GET, 'wx/v1/locale', data),
	// 绑定呼叫器或安全设备-新
	equipBinding: data => request(POST, 'wx/v1/customer/equipBinding', data),
	// 获取首页呼叫器和按键列表
	beeperAndBtnList: data => request(GET, 'wx/v1/beeper/homePage', data),
	// 获取呼叫器列表
	beeperList: data => request(GET, 'wx/v1/beeper/listIdName', data),
	// 通过当前位置获取呼叫器
	beeperByLngLat: data => request(GET, 'wx/v1/beeper/getIdByLngLat', data),
	// 获取自由呼叫器按键
	beeperFreeVirtual: data => request_v(GET, 'wx/v1/beeper/freeVirtual', data),
	// 一键出院
	btnEventAction: data => request(GET, 'wx/v1/beeper/btnEventAction', data),
	// 修改设备昵称
	UpdataName: data => request(PUT, 'wx/v1/equip/setNickName', data),
	// 修改场所昵称
	setNickName: data => request(PUT, 'wx/v1/locale/setNickName', data),
	// 开通场所邻里互助
	setHelpFlag: data => request(PUT, 'wx/v1/locale/setHelpFlag', data),
	//个人中心设置紧急联系人开通邻里互助
	setUserHelpFlag: data => request(PUT, 'wx/v1/userContact/setHelpFlag', data),

	// 设置默认选中
	setDefalutOpen: data => request(PUT, 'wx/v1/beeper/setDefaultOpen', data),
	// 接受邀请
	shareLocale: data => request(POST, 'wx/v1/locale/shareLocale', data),
	// 解绑场所
	unbindLocale: data => request(PUT, 'wx/v1/locale/unbindLocale', data),
	// // 提现
	// withdrawl:data => request(GET, '/api/wxWithdrawal', data),
	// 通过设备id来获取紧急联系人
	getDataByLocaleId: data => request(GET, 'wx/v1/localeContact', data),
	//通过用户id获取紧急联系人
	getDataByUserId: data => request(GET, 'wx/v1/userContact', data),
	// 提交紧急联系人
	setEquipContact: data => request(POST, 'wx/v1/localeContact/setLocaleContact', data),
	// 个人中心提交紧急联系人
	setUserContact: data => request(POST, 'wx/v1/userContact/setUserContact', data),
	// 用户提现记录
	cashOutRecord: data => request(GET, 'wx/v1/cashOut/page', data),
	// 用户余额查询
	getAmount: data => request(GET, 'wx/v1/cashOut/getCashOutAmount'),
	// 提现接口
	cashOut: data => request(GET, 'api/wxWithdrawal', data),
	// 会员余额
	listByCustomer: data => request(GET, 'wx/v1/member/listByCustomer'),

	// 服务功能键列表
	serverBtnList: data => request(GET, 'wx/v1/beeper/homePage', data),
	//获取商品列表
	getShopList: data => request(GET, 'wx/v1/beeperBtn/page', data),
	// 获取商户列表2
	getGoodsList: data => request(GET, 'wx/v1/beeperBtn/list', data),
	// 通过名字获取按键下的所有产品
	getGoodsListByName: data => request(GET, 'wx/v1/beeperBtn/pageGoodsByName', data),
	// 获取商品规格
	getSpecByGoodsId: data => request(GET, 'wx/v1/goodsSpec/getSpecByGoodsId', data),
	// 获取关联商品
	getRelationGoods: data => request(GET, 'wx/v1/goodsRelation/getMap', data),
	// 获取套餐组合
	getGoodsCombo: data => request(GET, 'wx/v1/goods/getGoodsCombo', data),
	// 商品详情
	getGoodsInfo: data => request(GET, 'wx/v1/goods', data),
	// 收藏商品
	setCollect: data => request(POST, 'wx/v1/userCollect/setCollect', data),
	// 通过功能按键和呼叫器获取商户列表
	getBusinessList: data => request(GET, 'wx/v1/business/listIdName', data),
	// 获取商户分类列表
	getBusinessClassifyList: data => request(GET, 'wx/v1/businessClassify/listCheckoutData', data),
	// 获取活动列表
	getActiveList: data => request(GET, 'wx/v1/active/listData', data),
	// 获取banners
	getBannerList: data => request(GET, 'wx/v1/banner/listIdName', data),
	//  订单支付
	orderPay: data => request(POST, 'wx/v1/order/shoppingAddOrder', data),
	// 通用键订单新增订单
	voiceAddOrder: data => request(POST, 'wx/v1/order/voiceAddOrder', data),
	// 订单操作记录
	orderOperation: data => request(GET, 'wx/v1/orderOperation/listByOrderId', data),
	// 保存收货地址
	saveAddress: data => request(POST, 'wx/v1/userHarvestAddress', data),
	// 收货地址列表
	addressList: data => request(GET, 'wx/v1/userHarvestAddress/listByUser', data),
	// 根据地址id获取地址详情
	getHarvestAddress: data => request(GET, 'wx/v1/userHarvestAddress', data),
	// 根据呼叫器id获取地址详情
	getBeeperAddress: data => request(GET, 'wx/v1/userHarvestAddress/getBeeperAddress', data),
	// 修改地址信息
	updateAddressInfo: data => request(PUT, 'wx/v1/userHarvestAddress', data),
	// 删除地址
	deleteAddressInfo: data => request(PUT, 'wx/v1/userHarvestAddress/delete', data),
	// 获取当前的收货地址
	getAddress: data => request(GET, 'wx/v1/userHarvestAddress/getAddress', data),
	// 设置默认地址
	setDefaultAddress: data => request(PUT, 'wx/v1/userHarvestAddress/setDefaultStart', data),
	// 获取全部市区县
	regionData: data => request(GET, '/wx/v1/area/listTwoThreeArea', data),
	// 通过省市区街道获取小区
	getVillageList: data => request(GET, 'wx/v1/village/listByName', data),
	// 获取包装费和配送费
	getCaculatePrice: data => request(POST, 'wx/v1/order/listCalculateData', data),
	// 获取自定义表单信息
	getFormInfo: data => request(GET, 'wx/v1/attr/listDataByIds', data),
	// 获取产品前置表单信息
	getFormItemInfo: data => request(GET, 'wx/v1/attr/listAttrByGS', data),
	// 编辑保存自定义表单信息
	editFormInfo: data => request(PUT, 'wx/v1/orderAttr/setOrderAttr', data),
	// 获取号源时段
	getListDoctorTime: data => request(GET, 'wx/v1/doctor/listDoctorTime', data),
	// 根据身份证获取用户数据
	getThirdPersonInfoByIdCard: data => request(GET, 'wx/v1/patientInfo/getDataByIdCard', data),
	// // 提交挂号信息
	// submitRegister:data=>request(POST,"wx/v1/register/doreg",data),
	// 再次下单获取的信息
	againOrderInfo: data => request(GET, 'wx/v1/order/againOrders', data),
	// 通过订单编号获取表单信息
	getFormInfoByOrder: data => request(GET, 'wx/v1/orderAttr/listData?orderId', data),
	// 获取套餐列表
	getCombineList: data => request(GET, 'wx/v1/combine/listData', data),
	// 获取套餐信息
	getCombineInfo: data => request(GET, 'wx/v1/combine', data),
	// 根据套餐id获取商品数据
	getGoodsListByCombinId: data => request(GET, 'wx/v1/combine/getCombineInfo', data),
	// 确认修改
	confirmModify: data => request(PUT, 'wx/v1/order/customerAffirmOrder', data),
	// 获取申请码列表
	getUserStackList: data => request(GET, 'wx/v1/userStack/page', data),
	// 获取推广员列表
	getPromoterList: data => request(GET, 'wx/v1/customer/pagePromote', data),
	// 查看推广码
	getPromoteCode: data => request(GET, 'wx/v1/customer/getPromoteCode', data),
	// 小区列表
	getVillageListPage: data => request(GET, 'wx/v1/village/page', data),
	// 小区列表idName
	getListVillage: data => request(GET, 'wx/v1/village/listIdName', data),
	// 删除小区资源
	delUserStack: data => request(PUT, 'wx/v1/userStack/delete', data),
	//  获取业务员手机号
	getSalePhone: data => request(GET, 'wx/v1/salesman/getPhoneByCustomerSale', data),
	//  绑定业务员
	bindingCmsSale: data => request(PUT, 'wx/v1/customer/bindingCmsSale', data),
	// 通过小区简码绑定呼叫器
	bindingByLinkCode: data => request(POST, 'wx/v1/beeper/bindingByLinkCode', data),
	// 小区详情
	getVillageDetail: data => request(GET, 'wx/v1/village', data),
	// 获取服务模板
	getServerModelList: data => request(GET, 'wx/v1/serverModel/listIdName', data),
	// 获取推广模板
	getPromoteModelList: data => request(GET, 'wx/v1/promoteModel/listIdName', data),
	// 生成申成码
	userStack: data => request(POST, 'wx/v1/userStack', data),
	// 扫推广码进来判断是否可以成为推广员
	customerScanCode: data => request(POST, 'wx/v1/customer/customerScanCode', data),
	// 批量保存设置生成码
	batchSetStack: data => request(POST, 'wx/v1/userStack/batchSetStack', data),
	// 未计算订单列表
	listWaitClearing: data => request(GET, 'wx/v1/order/listWaitClearing', data),
	// 计时开始或者结束
	timingOrderOperate: data => request(POST, 'wx/v1/order/timingOrderOperate', data),
	// 判断该按钮下最大数量产品的商户有多少产品
	countBtnGoods: data => request(GET, 'wx/v1/beeperBtn/countBtnGoods', data),
	// 判断改商户下面有多少产品
	countBusinessGoods: data => request(GET, 'wx/v1/beeperBtn/countBusinessGoods', data),
	// 获取银行列表
	listBankCode: data => request(GET, 'wx/v1/bankCode/listBankCode', data),
	// 获取银行支行列表
	listBranchCode: data => request(GET, 'wx/v1/bankCode/pageBranchCode', data),
	// 查询账户信息
	accountInfo: data => request(GET, 'wx/v1/accountInfo', data),
	// 修改账户信息
	setAccountInfo: data => request(POST, 'wx/v1/accountInfo/setAccountInfo', data),
	// 设置银行卡为结算卡
	bankSwitch: data => request(POST, 'wx/v1/accountInfo/bankSwitch', data),
	// 新增银行卡
	addBank: data => request(POST, 'wx/v1/accountInfo/addBank', data),
	// 银行卡列表
	getBankList: data => request(GET, 'wx/v1/accountInfo/listData', data),
	//设置信息
	setInfo: data => request(POST, 'wx/v1/accountInfo/setAccountInfo', data),
	//资金信息
	getUserAccount: data => request(GET, 'wx/v1/userAccount/getUserAccount', data),
	//收入明细
	userBill: data => request(GET, 'wx/v1/userBill/page', data),
	//提现记录
	getCashRecord: data => request(GET, '/wx/v1/cashRecord/page', data),
	//通过手机号获取翼码账户信息
	getDataByNameType: data => request(GET, '/wx/v1/accountInfo/getDataByNameType', data),
	//设置翼码账户信息
	setYmAccount: data => request(POST, '/wx/v1/accountInfo/setYmAccount', data),
	//获取翼码账户信息
	getYmAccount: data => request(GET, '/wx/v1/accountInfo/getYmAccount', data),
	//咨询分页
	getLibraryList: data => request(GET, '/wx/v1/library/page', data),
	//咨询信息
	getLibraryInfo: data => request(GET, '/wx/v1/library', data),
	//点赞差评
	clickActions: data => request(POST, '/wx/v1/library/clickActions', data),
	//标签列表
	getTagList: data => request(GET, '/wx/v1/tagInfo/listIdName', data),
	//标签列表
	listByLibrary: data => request(GET, '/wx/v1/goods/listByLibrary', data),
	//获取默认产品
	getBtnDefaultGoods: data => request(GET, '/wx/v1/beeperBtn/getBtnDefaultGoods', data),
	//默认产品下单
	simpleOrder: data => request(POST, '/wx/v1/order/simpleOrder', data),
	//补差价下单
	premiumOrder: data => request(POST, '/wx/v1/order/premiumOrder', data),
	// 活动报名
	activityList: data => request(GET, '/wx/v1/activity/page', data),
	// 活动子按钮列表
	listChildBtn: data => request(GET, '/wx/v1/activity/listChildBtn', data),
	// 通过按钮获取产品
	getGoodsByBtn: data => request(GET, '/wx/v1/activity/getGoodsByBtn', data),
	// 通过按钮获取产品
	setActivityRecord: data => request(POST, '/wx/v1/activity/setActivityRecord', data),
	// 通过按钮获取产品
	getActivityDetil: data => request(GET, '/wx/v1/activity', data),
	//点赞差评
	activityClickActions: data => request(POST, '/wx/v1/activity/clickActions', data),
	// 获取省、市、区、街道
	getListLevelData: data => request(GET, '/wx/v1/area/listLevelData', data),
	// 获取区域
	getResidentAddressList: data => request(GET, '/wx/v1/villageArea/idNameTree', data),
	// 获取个人基本信息
	getInfoDataByUser: data => request(GET, '/wx/v1/personInfo/getDataByUser', data),
	// 新增个人基本信息
	addInfoDataByUser: data => request(POST, '/wx/v1/personInfo', data),
	// 修改个人基本信息
	updateInfoDataByUser: data => request(PUT, '/wx/v1/personInfo', data),
	// 获取健康信息
	getHealthRecentData: data => request(GET, '/wx/v1/personHealth/getRecentData', data),
	// 新增健康信息
	addHealthRecentData: data => request(POST, '/wx/v1/personHealth', data),
	// 修改健康信息
	updateHealthRecentData: data => request(PUT, '/wx/v1/personHealth', data),
	// 健康打卡
	healthClock: data => request(POST, '/wx/v1/customer/healthClock', data),
	// 获取爱好信息
	getLoveDataByUser: data => request(GET, '/wx/v1/personLove/getDataByUser', data),
	// 新增爱好信息
	addLove: data => request(POST, '/wx/v1/personLove', data),
	// 修改爱好信息
	updateLove: data => request(PUT, '/wx/v1/personLove', data),
	// 获取关联的个人信息
	getPersonFamily: data => request(GET, '/wx/v1/personFamily', data),
	// 获取关联的个人信息列表
	getPersonFamilyList: data => request(GET, '/wx/v1/personFamily/page', data),
	// 新增关联的个人信息
	addPersonFamily: data => request(POST, '/wx/v1/personFamily', data),
	// 修改关联的个人信息
	updatePersonFamily: data => request(PUT, '/wx/v1/personFamily', data),
	// 设置联系人
	//  setContactData: data => request(PUT,"/wx/v1/beeper/setContactData", data),
	// 获取联系人
	getContactData: data => request(GET, '/wx/v1/beeperExtend/getData', data),
	// 获取服务员可工作时间段
	getWaiterRelationListTime: data => request(GET, '/wx/v1/serverWaiterRelation/listTime', data),
	//发送数据
	chatCompletions: (data, contextEnable = false) =>
		request(POST, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/ai/chat/completions?contextEnable=' + contextEnable,
			timeout: 600000
		}),
	// 语音转文字
	transcriptions: (filePath, data) =>
		uploadFile(undefined, filePath, data, {
			url: kiccBaseUrl + '/system_proxy/system/ai/audio/transcriptions',
			timeout: 600000
		}),
	// 文字转语音
	speech: data =>
		request(POST, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/ai/audio/speech',
			timeout: 600000
		}),
	// 获取消息记录
	chatMessage: data =>
		request(GET, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/ai/chat/message',
			timeout: 600000
		}),
	// 开启一条新的会话
	sessionSave: data =>
		request(POST, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/imSession/sessionSave'
		}),
	// 是否有新的会话，如果有的话就获取最近的一条会话
	lastSession: data =>
		request(GET, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/imSession/lastSession'
		}),
	// 更多
	imSessionremove: data =>
		request(GET, undefined, data, {
			url: kiccBaseUrl + '/system_proxy/system/imSessionremove'
		}),
	getUserByCasUserld: casUserId =>
		request(
			GET,
			undefined, {}, {
				header: {
					from: 'kG8qA6qG1aP5aR3g'
				},
				url: `${kiccBaseUrl}/system_proxy/system/user/oneClickAccess/${casUserId}`
			}
		),
	// 摄像头获取token
	getImouToken: data => request_imou(POST, 'accessToken', data),
	// 摄像头获取token
	getKitToken: data => request_imou(POST, 'getKitToken', data),
	// 获取临时权限校验秘钥
	createWeChatMiniProgramToken: data => request_imou(POST, 'createWeChatMiniProgramToken', data),
	// 创建Flv
	createDeviceFlvLive: data => request_imou(POST, 'createDeviceFlvLive', data),
	// 创建Rtmp
	createDeviceRtmpLive: data => request_imou(POST, 'createDeviceRtmpLive', data),
	// 查询Fiv
	queryDeviceFlvLive: data => request_imou(POST, 'queryDeviceFlvLive', data),
	// 通过设备id获取设备
	listDeviceDetailsByIds: data => request_imou(POST, 'listDeviceDetailsByIds', data),
	controlMovePTZ: data => request_imou(POST, 'controlMovePTZ', data),
	queryCloudRecords: data => request_imou(POST, 'queryCloudRecords', data),
	// 获取设备分类下设备列表
	BeeperBtnListSafety: data => request(GET, 'wx/v1/beeperBtn/listSafety', data),
	// 查询设备今日健康记录
	EquipTodayLog: data => request(GET, '/wx/v1/equipLog/health/today', data),
	// 分页查询设备健康检测日志
	EquipLogPage: data => request(GET, '/wx/v1/equipLog/health/page', data),
	// 查询呼叫器最近急救订单的急救数据
	GetRecentFirstAidOrder: data => request(GET, '/wx/v1/beeperBtn/getRecentFirstAidOrder', data),
	// (救援进度)查询急救订单分配的服务员
	ListFirstAidWaiter: data => request(GET, '/wx/v1/waiter/listFirstAidWaiter', data),
	// 通知详情
	noticeDetail: data => request(GET, '/wx/v1/sysNotify/getNewOne', data),
	//传id获取指定通知详情
	noticeDetail_Id: data => request(GET, '/wx/v1/sysNotify', data),
	// 通知列表
	noticeList: data => request(GET, '/wx/v1/sysNotify/page', data),
	// 通知明细
	noticeMx: data => request(GET, '/wx/v1/notifyTaskRecord/getList', data),
	//线下通知
	offlineNotice: data => request(PUT, '/wx/v1/sysNotify/offLineNotify', data),
	//一键重播
	onekeyReport: data => request(GET, '/wx/v1/sysNotify/againNotify', data),
	//通知统计
	statisticsList: data => request(GET, '/wx/v1/sysNotify/getNotifyCount', data),
	//受困情况-检验报警数据、根据报警记录以及上报情况返回数据
	checkoutAlarmAndTrapped: data => request(GET, '/wx/v1/alarmTrap/checkoutAlarmAndTrapped', data),
	//受困情况-新增受困情况数据
	sendReportAlarmTrap: data => request(POST, '/wx/v1/alarmTrap', data),
	// 通过呼叫器查询未结束的24小时内的报警集合
	listRecentNotEndByBeeper: data => request(GET, '/wx/v1/alarm/listRecentNotEndByBeeper', data),
	// 根据报警id查询受困上报集合
	ListDataAlarmTire: data => request(GET, '/wx/v1/alarmTrap/listData', data),
	// 根据报警id查询火情上报集合
	ListDataAlarmFire: data => request(GET, '/wx/v1/alarmFire/listData', data),
	// 火情上报-新增数据
	sendReportAlarmFire: data => request(POST, '/wx/v1/alarmFire', data),
	//微聊获取好友列表
	getMicroChatList: data => request(GET, '/wx/v1/beeperChar/getChatList', data),
	//删除微聊好友
	delMicroChatFriend: data => request(POST, '/wx/v1/beeperChar/deleteBeeperChat', data),
	//获取全网通呼叫器
	getAssignBeeper: data => request(GET, '/wx/v1/beeperChar/getCurrencyNetworkEquip', data),
	//新增微聊好友
	addMicroChatFriend: data => request(POST, '/wx/v1/beeperChar/saveBeeperChat', data),
	//修改微聊好友
	editMicroChatFriend: data => request(POST, '/wx/v1/beeperChar/updateBeeperChat', data),
	//设置语音识别
	setVoice: data => request(GET, '/wx/v1/beeper/cmdAction', data),
	// 根据呼叫器获取物业缴费信息
	getPropertyPaymentInfo: data => request(GET, '/wx/v1/beeperBtn/getPropertyPaymentInfo', data),
	// 根据呼叫器和月数获取该按钮默认产品商户的活动优惠内容
	getActivePreferential: data => request(GET, '/wx/v1/beeperBtn/getActivePreferential', data),
	// 物业缴费下单
	propertyPaymentInfoOrder: data => request(POST, '/wx/v1/order/propertyPaymentInfoOrder', data),
	// 获取辰溪预约转诊出院推送
	getOrderDischarge: data => request(GET, '/wx/v1/order/getOrderDischarge', data),
	//手表开始检测
	startDetection: data => request(GET, '/wx/v1/watch/checkSafetyNow', data),
	timingDetection: data => request(GET, '/wx/v1/watch/setSafetyParam', data),
	// 获取历史定时检测数据
	getDetectionData: data => request(GET, '/wx/v1/watch/getCheckRate', data),
	//开启定位
	openLocation: data => request(GET, '/wx/v1/watch/startSite', data),
	beeperOpenLocation: data => request(GET, '/wx/v1/beeper/startSite', data),
	//获取足迹
	getFootprintData: data => request(GET, '/wx/v1/watch/getTrack', data),
	//获取最新一条数据
	getFootprint: data => request(GET, '/wx/v1/equip/getSiteNow', data),
	//设置频率
	setFrequency: data => request(GET, '/wx/v1/watch/setSiteRate', data),
	//新增消防报警
	addFireDetection: data => request(POST, '/wx/v1/alarm/alarmReport', data),
	//呼叫器ID查询未结束的24小时内的报警集合
	getBeeperDetectionList: data => request(GET, '/wx/v1/alarm/listRecentNotEndByBeeper', data),
	//楼栋层门牌号查询未结束的24小时内的报警集合
	getHouseNumberDetectionList: data => request(GET, '/wx/v1/	alarm/listRecentNotEndByHouseNumber', data),
	// 获取消息数量
	checkoutIsReadCount: data => request(GET, '/wx/v1/remind/checkoutIsReadCount', data),
	// 消息已读接口
	setIsRead: data => request(GET, '/wx/v1/remind/setIsRead', data),
	// 获取用户在呼叫器下的地址
	getUserBeeperAddress: data => request(GET, '/wx/v1/userHarvestAddress/getAddressByUser', data),
	// 根据月份统计收入支出积分
	countByMonth: data => request(GET, '/wx/v1/customerPointsRecord/countByMonth', data),
	// 积分详情分页
	customerPointsPage: data => request(GET, '/wx/v1/customerPointsRecord/page', data),
	// 判断该商户下有没有摄像头
	checkoutBusinessCamera: data => request(GET, '/wx/v1/camera/checkoutBusinessCamera', data),
	// 查询商户绑定的摄像头
	listCameraByBusiness: data => request(GET, '/wx/v1/camera/listCameraByBusiness', data),
	//呼叫器设置备用电话
	setPhoneTwo: data => request(PUT, '/wx/v1/beeper/setBeeperPhoneTwo', data),
	//呼叫器开放搜索
	openSearch: data => request(GET, '/wx/v1/beeper/pageOpenSearch', data),
	//测试报警
	testAlarm: data => request(GET, '/wx/v1/equip/equipAnalogAlarm', data),
	//积分管理信息获取
	getUserIntegralAccount: data => request(GET, 'wx/v1/userAccount', data),
};

function request_imou(method, url, params) {
	params = {
		...params
	};
	if (url !== 'accessToken' && !params.token) {
		params.token = getApp().globalData.IMOU_TOKEN;
	}
	let requestTask = '';
	const time = parseInt(Date.now() / 1000);
	const nonce = makeRandom(32);
	const sign = `time:${time},nonce:${nonce},appSecret:${Storage.IMOU_APPSECRET}`;
	const signMd5 = md5.hexMD5(sign);
	const res = new Promise((resolve, reject) => {
		requestTask = wx.request({
			url: 'https://openapi.lechange.cn/openapi/' + url,
			method,
			timeout: 10000,
			data: {
				system: {
					ver: '1.0',
					appId: Storage.IMOU_APPID,
					sign: signMd5,
					nonce,
					time
				},
				id: nonce,
				params
			},
			success: function (res) {
				const code = res.data.result.code;
				if (code == 0) {
					resolve(res.data);
				} else {
					if (code == 'TK1002') {
						Toast.fail('请退出首页重新进入');
					} else {
						Toast.fail(res.data.result.msg);
					}
					reject(res.data.result);
				}
			},
			fail: reject,
			complete: res => {
				// wx.hideLoading()
			}
		});
	});
	res.requestTask = requestTask;
	return res;
}
module.exports = {
	API: API
	// env: __env == 'https://kicswx.kanglailab.com/' ? 'pro' : 'dev'
};